home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 January / PC Plus Super CD No55a (PCP-147A-1-99) (Disc 1) (1998).iso / linux / developers / visualtcl / windows / vtcl / lib / lib_blt.tcl < prev    next >
Encoding:
Text File  |  1997-10-23  |  4.9 KB  |  190 lines

  1. ##############################################################################
  2. #
  3. # lib_blt.tcl - blt widget support library
  4. #
  5. # Copyright (C) 1996-1997 Stewart Allen
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. # Architecture by Stewart Allen
  22. # Implementation by James Kramer usinge ideas from
  23. # Kenneth H. Cox <kcox@senteinc.com>
  24.  
  25. #
  26. # Initializes this library
  27. #
  28. #if {[info exist blt_library] == 1} {
  29. #    global auto_path blt_library
  30. #    lappend auto_path $blt_library
  31. #    catch {
  32. #        import add blt
  33. #    }
  34. #}
  35.  
  36. proc vTcl:widget:lib:lib_blt {args} {
  37.     global vTcl blt_library
  38.     #
  39.     # see if we're running bltWish. if not, return
  40.     #
  41.     if {[info exist blt_library] == 0} {
  42.         return
  43.     } else {
  44.         global auto_path blt_library tcl_version
  45.         lappend auto_path $blt_library
  46.         if {$tcl_version < 8} {
  47.             catch {
  48.                 import add blt
  49.             }
  50.         } else {
  51.             catch {
  52.                 package require BLT
  53.                 import add blt
  54.             }
  55.             catch {
  56.                 namespace import blt::*
  57.             }
  58.         }
  59.         
  60.     }
  61.  
  62.     # setup required variables
  63.     vTcl:lib_blt:setup
  64.  
  65.     # add items to toolbar
  66.     foreach i {
  67.         graph
  68.     } {
  69.         set img_file [file join $vTcl(VTCL_HOME) images icon_$i.gif]
  70.         if {![file exists $img_file]} {
  71.             set img_file [file join $vTcl(VTCL_HOME) images icon_tix_unknown.gif]
  72.         }
  73.         image create photo "ctl_$i" -file $img_file
  74.         vTcl:toolbar_add $i $i ctl_$i ""
  75.     }
  76.     # The Widget Browser needs images for all blt classes.
  77.     # The images need to be called, e.g. ctl_bltNoteBookFrame.
  78.     # Don't put these in the toolbar, because they are not commands,
  79.     # only classes.
  80. }
  81.  
  82. proc vTcl:lib_blt:setup {} {
  83.     global vTcl
  84.  
  85.     #
  86.     # additional attributes to set on insert
  87.     #
  88.     set vTcl(graph,insert)       "-background white -plotrelief groove -foreground black"
  89.  
  90.     #
  91.     # add to procedure, var, bind regular expressions
  92.     #
  93.     if {"$vTcl(bind,ignore)" != ""} {
  94.         append vTcl(bind,ignore) "|tix"
  95.     } else {
  96.         append vTcl(bind,ignore) "tix"
  97.     }
  98.     append vTcl(proc,ignore) "|tix"
  99.     append vTcl(var,ignore)  "|tix"
  100.  
  101.     #
  102.     # add to valid class list
  103.     #
  104.     lappend vTcl(classes) \
  105.         Graph
  106.  
  107.     #
  108.     # register additional options that might be on Blt widgets,
  109.     # and the option information that the Attribute Editor needs.
  110.     #
  111.     lappend vTcl(opt,list) \
  112.             -plotbackground \
  113.             -plotborderwidth \
  114.             -plotrelief \
  115.             -title 
  116.  
  117.     set vTcl(opt,-plotbackground) { {Plot BgColor}    Colors   color   {} }
  118.     set vTcl(opt,-plotborderwidth) { {Plot Width}        longname type    {} }
  119.     set vTcl(opt,-plotrelief)      { {Plot Relief}          {}       choice  {flat groove raised ridge sunken} }
  120.     set vTcl(opt,-title)          { Title               longname type    {} }
  121.     
  122.     #
  123.     # define dump procedures for widget types
  124.     #
  125.     set vTcl(Graph,dump_opt)         vTcl:lib_blt:dump_widget_opt
  126.  
  127.     #
  128.     # define whether or not do dump children of a class
  129.     #
  130.     set vTcl(Graph,dump_children)         0
  131. }
  132.  
  133. #
  134. # individual widget commands executed after insert
  135. #
  136. proc vTcl:widget:graph:inscmd {target} {
  137.     return ""
  138. }
  139.  
  140. proc vTcl:widget:graph:dblclick {target} {
  141.     puts "IN graph:dblclick"
  142. }
  143.  
  144. proc vTcl:widget:dump_graph {target basename} {
  145.     set results [vTcl:lib_blt:dump_widget_opt $target $basename]
  146.     puts "IN graph:dump_graph"
  147.     return $results
  148. }
  149.  
  150. #
  151. # per-widget-class dump procedures
  152. #
  153.  
  154. # Utility proc.  Ignore color options (-background, etc.) based on
  155. # preference.
  156. #
  157. # returns:
  158. #   1 means save the option
  159. #   0 means don't save it
  160. proc vTcl:lib_blt:save_option {opt} {
  161.         return 1
  162. }
  163.  
  164. # Utility proc.  Dump a blt widget.
  165. # Differs from vTcl:dump_widget_opt in that it tries harder to avoid
  166. # dumping options that shouldn't really be dumped, e.g. -fg,-bg,-font.
  167. proc vTcl:lib_blt:dump_widget_opt {target basename} {
  168.     global vTcl
  169.     set result ""
  170.     set class [vTcl:get_class $target]
  171.     set result "$vTcl(tab)[vTcl:lower_first $class] $basename"
  172.     set opt [$target configure]
  173.     set keep_opt ""
  174.     foreach e $opt {
  175.         if [vTcl:lib_blt:save_option $e] {
  176.             lappend keep_opt $e
  177.         }
  178.     }
  179.     set p [vTcl:get_opts $keep_opt]
  180.     if {$p != ""} {
  181.         append result " \\\n[vTcl:clean_pairs $p]\n"
  182.     } else {
  183.         append result "\n"
  184.     }
  185.     append result [vTcl:dump_widget_bind $target $basename]
  186.     return $result
  187. }
  188.  
  189.  
  190.